﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace SmartCommunity.Models;

public partial class SCDBContext : DbContext
{
    public SCDBContext(DbContextOptions<SCDBContext> options) : base(options)
    {
    }

    /// <summary>
    /// 小区
    /// </summary>
    public virtual DbSet<AreaEntity> Areas { get; set; }

    /// <summary>
    /// 附件表
    /// </summary>
    public virtual DbSet<AttachmentEntity> Attachments { get; set; }

    /// <summary>
    /// 楼宇
    /// </summary>
    public virtual DbSet<BuildingEntity> Buildings { get; set; }

    /// <summary>
    /// 社区
    /// </summary>
    public virtual DbSet<CommunityEntity> Communities { get; set; }

    /// <summary>
    /// 参数配置
    /// </summary>
    public virtual DbSet<ConfigEntity> Configs { get; set; }

    /// <summary>
    /// 数据字典
    /// </summary>
    public virtual DbSet<DictEntity> Dicts { get; set; }

    /// <summary>
    /// 字典明细
    /// </summary>
    public virtual DbSet<DictItemEntity> DictItems { get; set; }

    /// <summary>
    /// 操作日志
    /// </summary>
    public virtual DbSet<LogEntity> Logs { get; set; }

    /// <summary>
    /// 菜单
    /// </summary>
    public virtual DbSet<MenuEntity> Menus { get; set; }

    /// <summary>
    /// 角色
    /// </summary>
    public virtual DbSet<RoleEntity> Roles { get; set; }

    /// <summary>
    /// 房间
    /// </summary>
    public virtual DbSet<RoomEntity> Rooms { get; set; }

    /// <summary>
    /// 小区人员
    /// </summary>
    public virtual DbSet<RoomPersonEntity> RoomPersons { get; set; }

    /// <summary>
    /// 用户
    /// </summary>
    public virtual DbSet<UserEntity> Users { get; set; }

    /// <summary>
    /// 工单池
    /// </summary>
    public virtual DbSet<WorkOrderEntity> WorkOrders { get; set; }

    /// <summary>
    /// 工单处理过程记录
    /// </summary>
    public virtual DbSet<WorkProcessEntity> WorkProcesses { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .UseCollation("utf8mb4_0900_ai_ci")
            .HasCharSet("utf8mb4");

        modelBuilder.Entity<AreaEntity>(entity =>
        {
            entity.HasKey(e => e.AreaId).HasName("pk_scm_area");

            entity.ToTable("scm_area", tb => tb.HasComment("小区"));

            entity.HasIndex(e => e.CommunityId, "fk_area_community_id_idx");

            entity.Property(e => e.AreaId).HasCharSet("ascii").HasColumnName("area_id").UseCollation("ascii_general_ci").HasComment("小区ID");
            entity.Property(e => e.AreaName).HasColumnName("area_name").HasComment("小区名").HasMaxLength(100);
            entity.Property(e => e.CommunityId).HasCharSet("ascii").HasColumnName("community_id").UseCollation("ascii_general_ci").HasComment("社区ID");
            entity.Property(e => e.CommunityName).HasColumnName("community_name").HasComment("社区名称").HasMaxLength(100);
            entity.Property(e => e.AreaAddr).HasColumnName("area_addr").HasComment("小区地址").HasDefaultValue("").HasMaxLength(200);
            entity.Property(e => e.BuildArea).HasColumnName("build_area").HasComment("建筑面积").HasDefaultValueSql("'0.00'").HasPrecision(18, 2);
            entity.Property(e => e.PlantArea).HasColumnName("plant_area").HasComment("绿化面积").HasDefaultValueSql("'0.00'").HasPrecision(18, 2);
            entity.Property(e => e.TotalArea).HasColumnName("total_area").HasComment("占地面积(总面积)").HasDefaultValueSql("'0.00'").HasPrecision(18, 2);
            entity.Property(e => e.SortNo).HasColumnName("sort_no").HasComment("排序号");
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("小区简介").HasMaxLength(2000);
            entity.Property(e => e.Disabled).HasColumnName("disabled").HasComment("是否作废");
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasOne(d => d.Community).WithMany(p => p.Areas)
                .HasForeignKey(d => d.CommunityId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("fk_area_community_id");
        });

        modelBuilder.Entity<AttachmentEntity>(entity =>
        {
            entity.HasKey(e => e.AttachId).HasName("pk_sys_attachment");

            entity.ToTable("sys_attachment", tb => tb.HasComment("附件表"));

            entity.Property(e => e.AttachId).HasColumnName("attach_id").HasComment("附件ID").IsFixedLength().HasMaxLength(16);
            entity.Property(e => e.AttachType).HasColumnName("attach_type").HasComment("附件类型").HasMaxLength(45);
            entity.Property(e => e.BillId).HasColumnName("bill_id").HasComment("业务ID").IsFixedLength().HasMaxLength(16);
            entity.Property(e => e.FileName).HasColumnName("file_name").HasComment("文件名").HasMaxLength(200);
            entity.Property(e => e.FileType).HasColumnName("file_type").HasComment("文件类型(后缀)").HasMaxLength(45);
            entity.Property(e => e.FileSize).HasColumnName("file_size").HasComment("文件大小");
            entity.Property(e => e.FilePath).HasColumnName("file_path").HasComment("文件地址").HasMaxLength(200);
            entity.Property(e => e.IsPicture).HasColumnName("is_picture").HasColumnType("bit(1)").HasComment("是否图片").HasDefaultValueSql("b'0'");
            entity.Property(e => e.IsDeleted).HasColumnName("is_deleted").HasColumnType("bit(1)").HasComment("是否删除").HasDefaultValueSql("b'0'");
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
        });

        modelBuilder.Entity<BuildingEntity>(entity =>
        {
            entity.HasKey(e => e.BuildingId).HasName("pk_scm_building");

            entity.ToTable("scm_building", tb => tb.HasComment("楼宇"));

            entity.HasIndex(e => e.AreaId, "scm_building_area_id_idx");

            entity.HasIndex(e => e.ParentId, "scm_building_parent_id_idx");

            entity.Property(e => e.BuildingId).HasCharSet("ascii").HasColumnName("building_id").UseCollation("ascii_general_ci").HasComment("楼宇Id");
            entity.Property(e => e.AreaId).HasCharSet("ascii").HasColumnName("area_id").UseCollation("ascii_general_ci").HasComment("小区ID");
            entity.Property(e => e.ParentId).HasCharSet("ascii").HasColumnName("parent_id").UseCollation("ascii_general_ci").HasComment("上级id");
            entity.Property(e => e.BuildingNo).HasColumnName("building_no").HasComment("楼宇编号").HasMaxLength(20);
            entity.Property(e => e.BuildingName).HasColumnName("building_name").HasComment("楼宇名称").HasMaxLength(50);
            entity.Property(e => e.BuildingLevel).HasColumnName("building_level").HasComment("楼宇类型：楼栋1，单元楼2");
            entity.Property(e => e.BuildingType).HasColumnName("building_type").HasComment("建筑类型");
            entity.Property(e => e.BuildingUsage).HasColumnName("building_usage").HasComment("楼宇用途");
            entity.Property(e => e.BuildingDirection).HasColumnName("building_direction").HasComment("楼宇朝向");
            entity.Property(e => e.Floor).HasColumnName("floor").HasComment("层数");
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasOne(d => d.Area).WithMany(p => p.Buildings)
                .HasForeignKey(d => d.AreaId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("scm_building_area_id");

            entity.HasOne(d => d.Parent).WithMany(p => p.Children)
                .HasForeignKey(d => d.ParentId)
                .HasConstraintName("scm_building_parent_id");
        });

        modelBuilder.Entity<CommunityEntity>(entity =>
        {
            entity.HasKey(e => e.CommunityId).HasName("pk_scm_community");

            entity.ToTable("scm_community", tb => tb.HasComment("社区"));

            entity.Property(e => e.CommunityId).HasCharSet("ascii").HasColumnName("community_id").UseCollation("ascii_general_ci").HasComment("社区ID");
            entity.Property(e => e.CommunityName).HasColumnName("community_name").HasComment("社区名称").HasMaxLength(100);
            entity.Property(e => e.ManagerName).HasColumnName("manager_name").HasComment("负责人姓名").HasMaxLength(45);
            entity.Property(e => e.ManagerTel).HasColumnName("manager_tel").HasComment("负责人电话").HasMaxLength(20);
            entity.Property(e => e.CreatedDate).HasColumnName("created_date").HasComment("成立日期 ");
            entity.Property(e => e.Disabled).HasColumnName("disabled").HasComment("是否作废");
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);
        });

        modelBuilder.Entity<ConfigEntity>(entity =>
        {
            entity.HasKey(e => e.ConfigId).HasName("pk_sys_config");

            entity.ToTable("sys_config", tb => tb.HasComment("参数配置"));

            entity.HasIndex(e => e.ConfigKey, "uk_sys_config_config_key").IsUnique();

            entity.Property(e => e.ConfigId).HasColumnName("config_id").HasComment("参数ID");
            entity.Property(e => e.ConfigName).HasColumnName("config_name").HasComment("参数名称").HasMaxLength(50);
            entity.Property(e => e.ConfigKey).HasColumnName("config_key").HasComment("参数编码").HasMaxLength(100);
            entity.Property(e => e.ConfigValue).HasColumnName("config_value").HasComment("参数值").HasMaxLength(500);
            entity.Property(e => e.ExtField).HasColumnName("ext_field").HasComment("扩展字段").HasMaxLength(200);
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);
        });

        modelBuilder.Entity<DictEntity>(entity =>
        {
            entity.HasKey(e => e.DictId).HasName("pk_sys_dict");

            entity.ToTable("sys_dict", tb => tb.HasComment("数据字典"));

            entity.HasIndex(e => e.DictType, "uk_sys_dict_dict_type").IsUnique();

            entity.Property(e => e.DictId).HasColumnName("dict_id").HasComment("字典ID");
            entity.Property(e => e.DictType).HasColumnName("dict_type").HasComment("字典类别").HasMaxLength(50);
            entity.Property(e => e.DictName).HasColumnName("dict_name").HasComment("字典名称").HasMaxLength(50);
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);
        });

        modelBuilder.Entity<DictItemEntity>(entity =>
        {
            entity.HasKey(e => e.DictItemId).HasName("pk_sys_dict_item");

            entity.ToTable("sys_dict_item", tb => tb.HasComment("字典明细"));

            entity.HasIndex(e => e.DictId, "ix_sys_dict_item_dict_id");

            entity.Property(e => e.DictItemId).HasColumnName("dict_item_id").HasComment("字典明细ID");
            entity.Property(e => e.DictId).HasColumnName("dict_id").HasComment("字典ID");
            entity.Property(e => e.DictCode).HasColumnName("dict_code").HasComment("字典项编码").HasMaxLength(50);
            entity.Property(e => e.DictValue).HasColumnName("dict_value").HasComment("字典项键值").HasMaxLength(200);
            entity.Property(e => e.DictLabel).HasColumnName("dict_label").HasComment("字典项名称").HasMaxLength(50);
            entity.Property(e => e.SortNo).HasColumnName("sort_no").HasComment("排序号");
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.Disabled).HasColumnName("disabled").HasComment("是否作废");
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasOne(d => d.Dict).WithMany(p => p.DictItems)
                .HasForeignKey(d => d.DictId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("fk_sys_dict_item_dict_id");
        });

        modelBuilder.Entity<LogEntity>(entity =>
        {
            entity.HasKey(e => e.LogId).HasName("pk_sys_log");

            entity.ToTable("sys_log", tb => tb.HasComment("操作日志"));

            entity.Property(e => e.LogId).HasColumnName("log_id").HasComment("日志ID");
            entity.Property(e => e.OperateType).HasColumnName("operate_type").HasComment("操作类型");
            entity.Property(e => e.LogTitle).HasColumnName("log_title").HasComment("日志类别(简短描述)").HasMaxLength(50);
            entity.Property(e => e.LogContent).HasColumnName("log_content").HasComment("日志内容").HasDefaultValue("").HasMaxLength(2000);
            entity.Property(e => e.RequestPath).HasColumnName("request_path").HasComment("请求URL").HasMaxLength(200);
            entity.Property(e => e.RequestMethod).HasColumnName("request_method").HasComment("请求方式").HasMaxLength(10);
            entity.Property(e => e.RequestParam).HasColumnName("request_param").HasComment("请求参数").HasMaxLength(2000);
            entity.Property(e => e.Success).HasColumnName("success").HasComment("是否执行成功");
            entity.Property(e => e.ExecuteTime).HasColumnName("execute_time").HasComment("执行时长,毫秒");
            entity.Property(e => e.ClientIp).HasColumnName("client_ip").HasComment("客户端IP").HasMaxLength(20);
            entity.Property(e => e.ClientOs).HasColumnName("client_os").HasComment("客户端操作系统").HasMaxLength(50);
            entity.Property(e => e.ClientBrowser).HasColumnName("client_browser").HasComment("客户端浏览器").HasMaxLength(50);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("操作人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("操作时间").HasMaxLength(6);
        });

        modelBuilder.Entity<MenuEntity>(entity =>
        {
            entity.HasKey(e => e.MenuId).HasName("pk_sys_menu");

            entity.ToTable("sys_menu", tb => tb.HasComment("菜单"));

            entity.HasIndex(e => e.ParentId, "ix_sys_menu_parent_id");

            entity.Property(e => e.MenuId).HasColumnName("menu_id").HasComment("菜单ID");
            entity.Property(e => e.ParentId).HasColumnName("parent_id").HasComment("上级ID");
            entity.Property(e => e.MenuName).HasColumnName("menu_name").HasComment("菜单名称").HasMaxLength(50);
            entity.Property(e => e.MenuType).HasColumnName("menu_type").HasComment("菜单类型");
            entity.Property(e => e.MenuPath).HasColumnName("menu_path").HasComment("菜单地址").HasMaxLength(200);
            entity.Property(e => e.Permission).HasColumnName("permission").HasComment("权限标识").HasDefaultValue("").HasMaxLength(200);
            entity.Property(e => e.Icon).HasColumnName("icon").HasComment("菜单图标").HasMaxLength(100);
            entity.Property(e => e.SortNo).HasColumnName("sort_no").HasComment("排序号");
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasOne(d => d.Parent).WithMany(p => p.Children)
                .HasForeignKey(d => d.ParentId)
                .HasConstraintName("fk_sys_menu_parent_id");
        });

        modelBuilder.Entity<RoleEntity>(entity =>
        {
            entity.HasKey(e => e.RoleId).HasName("pk_sys_role");

            entity.ToTable("sys_role", tb => tb.HasComment("角色"));

            entity.HasIndex(e => e.RoleCode, "uk_sys_role_role_code").IsUnique();

            entity.Property(e => e.RoleId).HasColumnName("role_id").HasComment("角色ID");
            entity.Property(e => e.RoleCode).HasColumnName("role_code").HasComment("角色编码").HasMaxLength(50);
            entity.Property(e => e.RoleName).HasColumnName("role_name").HasComment("角色名称").HasMaxLength(50);
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.Disabled).HasColumnName("disabled").HasComment("是否作废");
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasMany(d => d.Menus).WithMany(p => p.Roles)
                .UsingEntity<Dictionary<string, object>>("RoleMenu",
                    r => r.HasOne<MenuEntity>().WithMany()
                        .HasForeignKey("MenuId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("fk_sys_role_menu_menu_id"),
                    l => l.HasOne<RoleEntity>().WithMany()
                        .HasForeignKey("RoleId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("fk_sys_role_menu_role_id"),
                    j =>
                    {
                        j.HasKey("RoleId", "MenuId")
                            .HasName("PRIMARY")
                            .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 });
                        j.ToTable("sys_role_menu", tb => tb.HasComment("角色菜单关联表"));
                        j.HasIndex(new[] { "MenuId" }, "ix_sys_role_menu_menu_id");
                        j.IndexerProperty<int>("RoleId").HasComment("角色ID").HasColumnName("role_id");
                        j.IndexerProperty<int>("MenuId").HasComment("菜单ID").HasColumnName("menu_id");
                    });
        });

        modelBuilder.Entity<RoomEntity>(entity =>
        {
            entity.HasKey(e => e.RoomId).HasName("pk_scm_room");

            entity.ToTable("scm_room", tb => tb.HasComment("房间"));

            entity.HasIndex(e => e.BuildingId, "scm_room_building_id_idx");

            entity.Property(e => e.RoomId).HasCharSet("ascii").HasColumnName("room_id").UseCollation("ascii_general_ci").HasComment("房间Id");
            entity.Property(e => e.BuildingId).HasCharSet("ascii").HasColumnName("building_id").UseCollation("ascii_general_ci").HasComment("楼栋ID");
            entity.Property(e => e.RoomNo).HasColumnName("room_no").HasComment("房号").HasMaxLength(20);
            entity.Property(e => e.RoomCode).HasColumnName("room_code").HasComment("完整房号").HasMaxLength(50);
            entity.Property(e => e.RoomFloor).HasColumnName("room_floor").HasComment("所在楼层");
            entity.Property(e => e.RoomUsage).HasColumnName("room_usage").HasComment("房间用途");
            entity.Property(e => e.RoomType).HasColumnName("room_type").HasComment("户型");
            entity.Property(e => e.RoomState).HasColumnName("room_state").HasComment("房间状态");
            entity.Property(e => e.RoomDeco).HasColumnName("room_deco");
            entity.Property(e => e.BuildArea).HasColumnName("build_area").HasComment("建筑面积").HasPrecision(18, 2);
            entity.Property(e => e.UsageArea).HasColumnName("usage_area").HasComment("使用面积").HasPrecision(18, 2);
            entity.Property(e => e.IsIdle).HasColumnName("is_idle").HasColumnType("bit(1)").HasComment("是否空置房");
            entity.Property(e => e.Manager).HasColumnName("manager").HasComment("户主").HasMaxLength(50);
            entity.Property(e => e.ManagerTel).HasColumnName("manager_tel").HasComment("户主电话").HasMaxLength(20);
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注说明").HasMaxLength(255);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasOne(d => d.Building).WithMany(p => p.Rooms)
                .HasForeignKey(d => d.BuildingId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("scm_room_building_id");
        });

        modelBuilder.Entity<RoomPersonEntity>(entity =>
        {
            entity.HasKey(e => e.PersonId).HasName("pk_scm_room_person");

            entity.ToTable("scm_room_person", tb => tb.HasComment("小区人员"));

            entity.HasIndex(e => e.RoomId, "room_person_room_id_idx");

            entity.Property(e => e.PersonId).HasCharSet("ascii").HasColumnName("person_id").UseCollation("ascii_general_ci").HasComment("人员ID");
            entity.Property(e => e.RoomId).HasCharSet("ascii").HasColumnName("room_id").UseCollation("ascii_general_ci").HasComment("房间ID");
            entity.Property(e => e.PersonName).HasColumnName("person_name").HasComment("人员姓名").HasMaxLength(45);
            entity.Property(e => e.PersonTel).HasColumnName("person_tel").HasComment("人员电话").HasMaxLength(45);
            entity.Property(e => e.IdCard).HasColumnName("id_card").HasComment("身份证号").HasMaxLength(45);
            entity.Property(e => e.Gender).HasColumnName("gender").HasComment("性别").IsFixedLength().HasMaxLength(1);
            entity.Property(e => e.IsManage).HasColumnName("is_manage").HasColumnType("bit(1)").HasComment("是否业主");

            entity.HasOne(d => d.Room).WithMany(p => p.RoomPersons)
                .HasForeignKey(d => d.RoomId)
                .HasConstraintName("room_person_room_id");
        });

        modelBuilder.Entity<UserEntity>(entity =>
        {
            entity.HasKey(e => e.UserId).HasName("pk_sys_user");

            entity.ToTable("sys_user", tb => tb.HasComment("用户"));

            entity.HasIndex(e => e.Username, "uk_sys_user_username").IsUnique();

            entity.Property(e => e.UserId).HasColumnName("user_id").HasComment("用户ID");
            entity.Property(e => e.Username).HasColumnName("username").HasComment("登录用户名").HasMaxLength(50);
            entity.Property(e => e.Nickname).HasColumnName("nickname").HasComment("昵称").HasMaxLength(50);
            entity.Property(e => e.Password).HasColumnName("password").HasComment("登录密码").HasMaxLength(255);
            entity.Property(e => e.Cellphone).HasColumnName("cellphone").HasComment("手机号码").HasMaxLength(20);
            entity.Property(e => e.Email).HasColumnName("email").HasComment("电子邮箱").HasMaxLength(80);
            entity.Property(e => e.Gender).HasColumnName("gender").HasComment("性别：M/F/O").IsFixedLength().HasMaxLength(1);
            entity.Property(e => e.Disabled).HasColumnName("disabled").HasComment("是否作废");
            entity.Property(e => e.Status).HasColumnName("status").HasComment("用户状态:0正常；1密码锁定；2密码过期；");
            entity.Property(e => e.Avatar).HasColumnName("avatar").HasComment("头像").HasMaxLength(200);
            entity.Property(e => e.Remark).HasColumnName("remark").HasComment("备注").HasMaxLength(255);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasMany(d => d.Roles).WithMany(p => p.Users)
                .UsingEntity<Dictionary<string, object>>("UserRole",
                    r => r.HasOne<RoleEntity>().WithMany()
                        .HasForeignKey("RoleId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("fk_sys_user_role_role_id"),
                    l => l.HasOne<UserEntity>().WithMany()
                        .HasForeignKey("UserId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("fk_sys_user_role_user_id"),
                    j =>
                    {
                        j.HasKey("UserId", "RoleId")
                            .HasName("PRIMARY")
                            .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 });
                        j.ToTable("sys_user_role", tb => tb.HasComment("用户角色关联表"));
                        j.HasIndex(new[] { "RoleId" }, "ix_sys_user_role_role_id");
                        j.IndexerProperty<int>("UserId").HasComment("用户ID").HasColumnName("user_id");
                        j.IndexerProperty<int>("RoleId").HasComment("角色ID").HasColumnName("role_id");
                    });
        });

        modelBuilder.Entity<WorkOrderEntity>(entity =>
        {
            entity.HasKey(e => e.OrderId).HasName("pk_scm_work_order");

            entity.ToTable("scm_work_order", tb => tb.HasComment("工单池"));

            entity.Property(e => e.OrderId).HasCharSet("ascii").HasColumnName("order_id").UseCollation("ascii_general_ci").HasComment("工单ID");
            entity.Property(e => e.OrderNo).HasColumnName("order_no").HasComment("工单编号").HasMaxLength(45);
            entity.Property(e => e.OrderType).HasColumnName("order_type").HasComment("工单类型");
            entity.Property(e => e.Description).HasColumnName("description").HasComment("工单描述").HasMaxLength(4000);
            entity.Property(e => e.OrderStatus).HasColumnName("order_status").HasComment("工单状态");
            entity.Property(e => e.SubmitPerson).HasColumnName("submit_person").HasComment("提交人").HasMaxLength(45);
            entity.Property(e => e.SubmitTel).HasColumnName("submit_tel").HasComment("提交人电话").HasMaxLength(45);
            entity.Property(e => e.SubmitAreaId).HasCharSet("ascii").HasColumnName("submit_area_id").UseCollation("ascii_general_ci").HasComment("小区ID");
            entity.Property(e => e.SubmitRoomId).HasCharSet("ascii").HasColumnName("submit_room_id").UseCollation("ascii_general_ci").HasComment("提交人房号");
            entity.Property(e => e.SubmitAddr).HasColumnName("submit_addr").HasComment("提交人地址").HasMaxLength(45);
            entity.Property(e => e.SubmitTime).HasColumnName("submit_time").HasColumnType("datetime").HasComment("提交时间");
            entity.Property(e => e.RateStars).HasColumnName("rate_stars").HasComment("评价星级");
            entity.Property(e => e.RateContent).HasColumnName("rate_content").HasComment("评价内容").HasMaxLength(2000);
            entity.Property(e => e.HandleUser).HasColumnName("handle_user").HasComment("工单处理人账号");
            entity.Property(e => e.HandleUserName).HasColumnName("handle_user_name").HasComment("工单处理人姓名").HasMaxLength(45);
            entity.Property(e => e.HandleResult).HasColumnName("handle_result").HasComment("处理结果").HasMaxLength(2000);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);
        });

        modelBuilder.Entity<WorkProcessEntity>(entity =>
        {
            entity.HasKey(e => e.ProcessId).HasName("pk_scm_work_process");

            entity.ToTable("scm_work_process", tb => tb.HasComment("工单处理过程记录"));

            entity.HasIndex(e => e.OrderId, "work_process_order_id_idx");

            entity.Property(e => e.ProcessId).HasCharSet("ascii").HasColumnName("process_id").UseCollation("ascii_general_ci").HasComment("处理过程ID");
            entity.Property(e => e.OrderId).HasCharSet("ascii").HasColumnName("order_id").UseCollation("ascii_general_ci").HasComment("工单id");
            entity.Property(e => e.Content).HasComment("处理内容描述").HasMaxLength(2000);
            entity.Property(e => e.CreatedBy).HasColumnName("created_by").HasComment("创建人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.CreatedTime).HasColumnName("created_time").HasComment("创建时间").HasMaxLength(6);
            entity.Property(e => e.UpdatedBy).HasColumnName("updated_by").HasComment("修改人").HasDefaultValue("").HasMaxLength(50);
            entity.Property(e => e.UpdatedTime).HasColumnName("updated_time").HasComment("修改时间").HasMaxLength(6);

            entity.HasOne(d => d.Order).WithMany(p => p.WorkProcesses)
                .HasForeignKey(d => d.OrderId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("work_process_order_id");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
